// pages/topup/topup.js
var current
Page({

  /**
   * 页面的初始数据
   */
  data: {
    coin1: 150,
    coin2: 300,
    coin3: 600,
    coin4: 1500,
    num: 0,//nav样式初始化
    coinNum: 1,//数量初始化
    coinToalPay: 30,//总数初始化
    showModal: false, //支付方式Dialog初始化
    value1:'wechat',
    value2: 'balance',
    checked1:'ture', 
    checked2:'',
    balanceAll:100
  },

  // nav样式切换
  changeNav: function (e) {
    var that = this;
    current = (e.target.dataset.current)/5;
    var num = e.target.dataset.num
    var currentNumber = that.data.coinNum
    that.setData({
      num: num,
      coinToalPay: current * currentNumber
    }) 
  },

  //减少数量
  subCoinNum: function (e) {
    var that = this;
    var currentNum = that.data.coinNum;
    if (currentNum <= 1) {
      return;
    }
    that.setData({
      coinNum: (currentNum - 1),
      coinToalPay: (current * (currentNum - 1))
    });
  },

  //增加数量
  addCoinNum: function (e) {
    // debugger
    var that = this;
    var currentNum = that.data.coinNum;
    that.setData({
      coinNum: (currentNum + 1),
      coinToalPay: (current * (currentNum+1))
    });
  },

  //支付方式Dialog
  installPay: function (e) {
    this.setData({
      showModal: true
    })
  },

  // Dialog确认按钮点击事件
  onConfirm: function () {
    this.setData({
      showModal: false
    });
  },

  //点击遮幕层Dialog消失
  bindMask: function (e) {
    this.setData({
      showModal: false
    })
  },

  // 选择支付方式
  radioChange(e) {
    var that = this
    var value = e.detail.value
    var value1 = that.data.value1
    var value2 = that.data.value2
    var checked1 = that.data.checked1
    var checked2 = that.data.checked2
    if (value == value2){
      that.showDialogBtn()
      checked2 = 'true'
      checked1 = ''
    }else{
      checked2 = ''
      checked1 = 'true'
    }
    that.setData({
      checked1: checked1,
      checked2: checked2
    });
  },

  //判断是否使用余额支付
  showDialogBtn: function (e) {
    var that = this
    wx.showModal({
      content: '是否确认使用余额支付',
      cancelText:'取消',
      cancelColor:'#e60011',
      confirmText: '立即使用',
      confirmColor:'#e60011',
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    current = 30//初始data-current值
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})